package com.qf.springboot.aspect;

import com.qf.springboot.exhandler.ParamBullException;
import com.qf.springboot.utils.Constants;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Component
@Aspect
@Slf4j
public class NullValidateAspect {
    @Pointcut("@annotation(com.qf.springboot.annotation.NullValidation)")
    public void myPointcut() {

    }

    @Before("myPointcut()")
    public void before(JoinPoint joinPoint) {
        log.debug("校验是否为空");
        Object[] args = joinPoint.getArgs();
        for (Object arg : args) {
            if (null == arg) {
                log.error("参数为空");
                throw new ParamBullException(Constants.FAIL_CODE, "参数为空");
            }
        }
    }
}
